<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<base href="${CONTEXT_PATH}/" />
<title>学生信息管理</title>
	<link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.4.1/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.4.1/themes/icon.css">
	<script type="text/javascript" src="js/jquery-easyui-1.4.1/jquery.min.js"></script>
	<script type="text/javascript" src="js/jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="js/jquery-easyui-1.4.1/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript">
    	function searchStudent() {
    		$('#dg').datagrid('load', {
				stuNo:$('#stuNo').val(),
				stuName:$('#stuName').val(),
				sex:$('#sex').combobox('getValue'),
				bbirthday:$('#bbirthday').datebox('getValue'),
				ebirthday:$('#ebirthday').datebox('getValue'),
				gradeId:$('#gradeId').combobox('getValue')
    		});
    	}
    	function removeStudent() {
    		var selectedRows = $('#dg').datagrid('getSelections');
    		if(selectedRows.length == 0) {
    			$.messager.alert("系统提示", "请选择要删除的数据！");
    			return;
    		}
    		var strIds = [];
    		for(var i=0; i<selectedRows.length; i++) {
    			strIds.push(selectedRows[i].stuId);
    		}
    		var ids = strIds.join(',');
    		$.messager.confirm("系统提示", "您确定要删除这<font color=red>" + selectedRows.length + "</font>条数据吗？", function(r) {
    			if(r) {
    				$.post("student/remove", {delIds:ids}, function(result) {
    					if(result.success) {
    						$.messager.alert('系统提示', '您已成功删除<font color=red>' + result.delNums + '</font>条数据！');
    						$('#dg').datagrid('reload');
    					} else {
    						$.messager.alert('系统提示', result.errorMsg);
    					}
    				}, 'json');
    			}
    		});
    	}
    	function openStudentCreateDialog() {
    		$('#dlg').dialog('open').dialog('setTitle', '添加学生信息');
    		$('#fm').form('clear');
    		url = 'student/createOrUpdate';
    	}
    	function openStudentUpdateDialog() {
    		var selectedRows = $('#dg').datagrid('getSelections');
    		if(selectedRows.length != 1) {
    			$.messager.alert('系统提示', '请选择一条要编辑的数据！');
    			return;
    		}
    		//采用ajax取值方式一 修改了jfinal getModel
    		$('#dlg').dialog('open').dialog('setTitle', '修改学生信息');
    		var row = selectedRows[0];
    		$('#fm').form('load', row);
    		url = 'student/createOrUpdate?stuId='+row.stuId;
    	}
    	function createStudent() {
    		$('#fm').form('submit', {
    			url:url,
    			onSubmit:function() {
    				return $(this).form('validate');
    			},
    			success:function(result) {
    				result = eval('(' + result + ')');
    				if(result.success) {
    					$.messager.alert('系统提示', '保存成功！');
    					closeStudentDialog();
    					$('#dg').datagrid('reload');
    				} else {
    					$.messager.alert('系统提示', result.errorMsg);
    				}
    			}
    		});
    	}
    	function closeStudentDialog() {
    		$('#dlg').dialog('close');
    	}
    </script>
</head>
<body style="margin: 5px;">
	
	<table id="dg" title="学生信息" class="easyui-datagrid" fitColumns="true"
		pagination="true" rownumbers="true" fit="true" url="student/read" toolbar="#tb">
		<thead>
			<tr>
				<th field="cb" checkbox="true"></th>
				<th field="stuId" width="50" align="center">编号</th>
				<th field="stuNo" width="100" align="center">学号</th>
				<th field="stuName" width="100" align="center">姓名</th>
				<th field="sex" width="100" align="center">性别</th>
				<th field="birthday" width="100" align="center">出生日期</th>
				<th field="gradeName" width="100" align="center">班级名称</th>
				<th field="email" width="150" align="center">Email</th>
				<th field="stuDesc" width="250" align="center">学生备注</th>
			</tr>
		</thead>
	</table>
	<div id="tb">
		<div>
			<a href="javascript:openStudentCreateDialog()" class="easyui-linkbutton" iconCls="icon-add" plain="true">添加</a>
			<a href="javascript:openStudentUpdateDialog()" class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a>
			<a href="javascript:removeStudent()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
		</div>
		<div>
			&nbsp;学号：&nbsp;<input type="text" name="stuNo" id="stuNo" size="10"/>
			&nbsp;姓名：&nbsp;<input type="text" name="stuName" id="stuName" size="10"/>
			&nbsp;性别：&nbsp;<select class="easyui-combobox" name="sex" id="sex" editable="false" panelHeight="auto">
				<option value="">请选择...</option>
				<option value="男">男</option>
				<option value="女">女</option>
			</select>
			&nbsp;出生日期：&nbsp;<input class="easyui-datebox" name="bbirthday" id="bbirthday" editable="false" size="10"/>-><input class="easyui-datebox" name="conditions.ebirthday" id="ebirthday" editable="false" size="10"/>
			&nbsp;所属班级：&nbsp;<input class="easyui-combobox" name="gradeId" id="gradeId" size="10" data-options="panelHeight:'auto',editable:false,valueField:'id',textField:'gradeName',url:'grade/readComboList'"/>
			
			<a href="javascript:searchStudent()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a> 
		</div>
	</div>
	<div id="dlg" class="easyui-dialog" style="width: 570;height: 350;padding: 10px 20px"
		closed="true" buttons="#dlg-buttons">
		<form id="fm" method="post" >
			<table cellspacing="5px;" >
	    		<tr>
	    			<td><font size="2">学号：</font></td>
	    			<td><input type="text" name="stuNo" id="stuNo" class="easyui-validatebox" required="ture"/></td>
	    			<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
	    			<td><font size="2">姓名：</font></td>
	    			<td><input type="text" name="stuName" id="stuName" class="easyui-validatebox" required="ture"/></td>
	    		</tr>
	    		<tr>
	    			<td><font size="2">性别：</font></td>
	    			<td><select class="easyui-combobox" id="sex" name="sex" editable="false" panelHeight="auto" style="width: 172px">
		    			<option value="">请选择...</option>
		    			<option value="男">男</option>
		    			<option value="女">女</option>
		    		</select></td>
	    			<td></td>
	    			<td><font size="2">出生日期：</font></td>
	    			<td><input class="easyui-datebox" name="birthday" id="birthday" required="ture" editable="false" /></td>
	    		</tr>
	    		<tr>
	    			<td><font size="2">班级名称：</font></td>
	    			<td><input class="easyui-combobox" id="gradeId" name="gradeId" data-options="panelHeight:'auto',editable:false,valueField:'id',textField:'gradeName',url:'grade/readComboList'"/></td>
	    			<td></td>
	    			<td><font size="2">Email：</font></td>
	    			<td><input type="text" name="email" id="email" class="easyui-validatebox" required="ture" validType="email"/></td>
	    		</tr>
	    		<tr>
	    			<td valign="top"><font size="2">学生备注：</font></td>
	    			<td colspan="4"><textarea rows="7" cols="50" name="stuDesc" id="stuDesc"></textarea></td>
	    		</tr>
    		</table>
		</form>
	</div>
	<div id="dlg-buttons">
		<a href="javascript:createStudent()" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
		<a href="javascript:closeStudentDialog()" class="easyui-linkbutton" iconCls="icon-cancel">取消</a>
	</div>
</body>
</html>